package com.example.demorabbitmq.test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Map;

import static com.example.demorabbitmq.config.RabbitConfig.TEST_QUEUE_NAME_1;
import static com.example.demorabbitmq.config.RabbitConfig.TEST_QUEUE_NAME_2;


/**
 * @author wangbin
 */
@Component
@Slf4j
public class ConsumerController {
    @RabbitListener(queues = TEST_QUEUE_NAME_1 + ".queue")
    public void testQueue1(String message) {
        int i = 1 / 0; // 测试处理消息发生错误时的逻辑
        log.info("testQueue1 收到消息：{}", message);
    }

    @RabbitListener(queues = TEST_QUEUE_NAME_2 + ".queue")
    public void testQueue2(Map<String, Object> message) throws JsonProcessingException {
        log.info("testQueue2 收到消息：{}", new ObjectMapper().writeValueAsString(message));
    }

}
